package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDTO;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 护理计划表(NursingPlan)表服务实现类
 *
 * @author makejava
 * @since 2024-10-05 18:15:09
 */
@Service
public class NursingPlanServiceImpl implements NursingPlanService {
    @Resource
    private NursingPlanMapper NursingPlanMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public NursingPlan queryById(Integer id) {
        return this.NursingPlanMapper.queryById(id);
    }


    /**
     * 修改数据
     *
     * @param nursingPlan 实例对象
     * @return 实例对象
     */
    @Override
    public NursingPlan update(NursingPlan nursingPlan) {
        this.NursingPlanMapper.update(nursingPlan);
        return this.queryById(nursingPlan.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.NursingPlanMapper.deleteById(id) > 0;
    }

    @Override
    public PageResponse<NursingPlanVO> searchByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingPlanVO> nursingLevels = NursingPlanMapper.searchByPage(name, status);
        return PageResponse.of(nursingLevels, NursingPlanVO.class);
    }

    @Override
    public ResponseResult insert(NursingPlanDTO dto, Long userIdByName) {
        NursingPlan nursingPlan = new NursingPlan();
        nursingPlan.setCreateBy(userIdByName);
        nursingPlan.setStatus(1);
        nursingPlan.setPlanName(dto.getPlanName());
        String string = dto.getProjectPlans().toString();
        nursingPlan.setRemark(string);
        nursingPlan.setCreateTime(LocalDateTime.now());
        NursingPlanMapper.insert(nursingPlan);
        return ResponseResult.success();
    }
}
